package com.example.findu;


import com.findu.control.Public_title_dynamic;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.AnimationUtils;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;


/**
 * 
 * @ClassName: More_Home_Man
 * @Description: TODO(更多页面--家谱管理)
 * @author hgf
 * @date 2015-11-5 下午2:30:07
 * 
 */
public class More_Home_Manage extends Activity implements OnClickListener{
	// 标题控制
	private Public_title_dynamic public_title;
	// 声明title布局
	private View include_view;

	//声明意图
	private Intent intent;
	//声明popu
	private PopupWindow mpopupWindow;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_more__home__manage);
		
		init_title();

	}

	/**
	 * 初始化title
	 */
	private void init_title() {
		// 初始化title
		include_view = findViewById(R.id.More_Home_Man_include);
		public_title = new Public_title_dynamic(include_view); // 新建工具类设置布局控件

		// title详细设置
		public_title.setTextLeft("设置");
		public_title.setTextView("设置");
		public_title.setTextRight_Gone();
		public_title.setRighttImage(R.drawable.add);
		
		ImageView image_left = (ImageView) include_view.findViewById(R.id.public_title_dynamic__liftImage);
		image_left.setOnClickListener(this);
		ImageView image_right = (ImageView) include_view.findViewById(R.id.public_title_dynamic_rightImage);
		image_right.setOnClickListener(this);
	}

	/**
	 * 监听事件
	 * @param arg0
	 */
	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		switch (arg0.getId()) {
		case R.id.public_title_dynamic__liftImage:
			finish();
			break;
		case R.id.public_title_dynamic_rightImage:
			showPopMenu();
			break;
		case R.id.rl_weixin:

		
			mpopupWindow.dismiss();
			break;
		case R.id.rl_weibo:
			intent = new Intent(More_Home_Manage.this,new Home_More_homeManage_genealogyShow().getClass());		
			startActivity(intent);
			
			mpopupWindow.dismiss();
			break;
		case R.id.rl_duanxin:

			mpopupWindow.dismiss();
			break;
		case R.id.bt_cancle:

			mpopupWindow.dismiss();
			finish();
			break;
		default:
			break;
		}
	}
	
	/**
	 * popup初始化
	 */
	private void showPopMenu() {
		View view = View.inflate(getApplicationContext(),
				R.layout.home_more_homemanager_popup_menu, null);
		RelativeLayout rl_weixin = (RelativeLayout) view
				.findViewById(R.id.rl_weixin);
		RelativeLayout rl_weibo = (RelativeLayout) view
				.findViewById(R.id.rl_weibo);
		RelativeLayout rl_duanxin = (RelativeLayout) view
				.findViewById(R.id.rl_duanxin);
		Button bt_cancle = (Button) view.findViewById(R.id.bt_cancle);

		rl_weixin.setOnClickListener(this);
		rl_weibo.setOnClickListener(this);
		rl_duanxin.setOnClickListener(this);
		bt_cancle.setOnClickListener(this);

		//单击其它地方执行
		view.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				mpopupWindow.dismiss();
			}
		});

		view.startAnimation(AnimationUtils.loadAnimation(
				getApplicationContext(), R.anim.fade_in));
		LinearLayout ll_popup = (LinearLayout) view.findViewById(R.id.ll_popup);
		ll_popup.startAnimation(AnimationUtils.loadAnimation(
				getApplicationContext(), R.anim.push_bottom_in));

		if (mpopupWindow == null) {
			mpopupWindow = new PopupWindow(this);
			mpopupWindow.setWidth(LayoutParams.MATCH_PARENT);
			mpopupWindow.setHeight(LayoutParams.MATCH_PARENT);
			mpopupWindow.setBackgroundDrawable(new BitmapDrawable());

			mpopupWindow.setFocusable(true);
			mpopupWindow.setOutsideTouchable(true);
		}

		mpopupWindow.setContentView(view);
		mpopupWindow.showAtLocation(include_view, Gravity.BOTTOM, 0, 0);
		mpopupWindow.update();
	}
}
